/**
 * Project Name:jiuselu-parent
 * File Name:RandomUtils.java
 * Package Name:com.fxp.project.jiuselu.commons.utils
 * Date:2021年11月18日 15:27
 * Copyright (c) 2021, Kai.Wang All Rights Reserved.
 */
package com.fxp.project.jiuselu.commons.utils;

import com.fxp.project.jiuselu.commons.date.DateUtil;

/**
 * ClassName:RandomUtils<br/>
 * Function: 随机数创建工具类<br/>
 * Date:2021年11月18日 15:27<br/>
 *
 * @author Kai.Wang
 * @version 1.0.0
 * @see
 * @since JDK 8
 */
public class RandomUtils {
    private static final String RANDOM_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private static final String RANDOM_NUMBER = "0123456789";

    private static final java.util.Random RANDOM = new java.util.Random();

    public static String getRandomStr() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 16; i++) {
            sb.append(RANDOM_STR.charAt(RANDOM.nextInt(RANDOM_STR.length())));
        }
        return sb.toString();
    }

    public static String getRandomStr(int j) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < j; i++) {
            sb.append(RANDOM_STR.charAt(RANDOM.nextInt(RANDOM_STR.length())));
        }
        return sb.toString();
    }

    public static String getRandomNumber() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 16; i++) {
            sb.append(RANDOM_NUMBER.charAt(RANDOM.nextInt(RANDOM_NUMBER.length())));
        }
        return sb.toString();
    }

    public static String getRandomNumber(int j) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < j; i++) {
            sb.append(RANDOM_NUMBER.charAt(RANDOM.nextInt(RANDOM_NUMBER.length())));
        }
        return sb.toString();
    }

    /**
     * getRequestNo: 获取请求的流水号. <br/>
     *
     * @return
     * @author Jason.Wang
     * @version 1.0
     * @since JDK1.7
     */
    public static String getRequestNo() {
        return String.format("Q%s", DateUtil.getCodeNo(), getRandomStr(2));
    }

    /**
     * getOrderNo: 获取随机的订单号. <br/>
     *
     * @return
     * @author Jason.Wang
     * @version 1.0
     * @since JDK1.7
     */
    public static String getOrderNo() {
        return String.format("%s", DateUtil.getCodeNo(), getRandomStr(2));
    }
}